5 '----------- PC BATTLE OF NUMBERS GAME ------------
8 '
10 KEY OFF: CLS
20 DEFINT C, I, M, P, T, X
30 RANDOMIZE VAL(RIGHT$(TIME$, 2))
40 M = INT(4 * RND + 5)
50 T = INT(19 * RND + 17)
55 LOCATE 25, 25
60 PRINT CHR$(16); CHR$(16); CHR$(16); " THE BATTLE OF NUMBERS ";
70 PRINT CHR$(17); CHR$(17); CHR$(17);
75 LOCATE 1, 1
80 PRINT "THIS GAME PITS YOU AGAINST THE PC IN A TEST OF ";
90 PRINT "MATHMATICAL SKILL. TWO NUMBERS,"
100 PRINT "ONE SEVERAL TIMES LARGER THAN THE OTHER,HAVE ";
110 PRINT "BEEN SELECTED AT RANDOM. BY TURNS"
120 PRINT "BOTH YOU AND THE COMPUTER SUBTRACT AN INTERGER ";
130 PRINT "BETWEEN 1 AND";
140 COLOR 31, 0: PRINT M; : COLOR 7, 0: PRINT "FROM THE TOTAL"
150 PRINT "LISTED BELOW UNTIL ZERO IS LEFT. WHOEVER MUST ";
160 PRINT "MAKE THE FINAL SUBTRACTION IS THE"
170 PRINT "LOSER. UNLESS YOU EMPLOY A RATIONAL STRATEGY,";
180 PRINT " THE COMPUTER WILL TROUNCE YOU"
190 PRINT "EVERY TIME, AND GLOAT ABOUT IT, TOO. ";
200 PRINT "THE FIRST TURN IS YOURS -- GOOD LUCK!"
210 PRINT CHR$(201); STRING$(28, 205); CHR$(203);
220 PRINT STRING$(20, 205); CHR$(203); STRING$(28, 205); CHR$(187);
230 PRINT CHR$(186); TAB(30); CHR$(186); TAB(38);
240 PRINT "TOTAL"; TAB(51); CHR$(186); TAB(80); CHR$(186);
250 PRINT CHR$(186); TAB(30); CHR$(199);
260 PRINT STRING$(20, 196); CHR$(182); TAB(80); CHR$(186);
270 FOR I = 10 TO 22
280    LOCATE I, 1
290    PRINT CHR$(186); TAB(30); CHR$(186); TAB(51);
300    PRINT CHR$(186); TAB(80); CHR$(186);
310 NEXT I
315 PRINT CHR$(200); STRING$(28, 205); CHR$(202);
317 PRINT STRING$(20, 205); CHR$(202); STRING$(28, 205); CHR$(188);
320 PC$ = CHR$(19) + " PC WINS " + CHR$(19)
330 PLAYER$ = CHR$(19) + " YOU WIN " + CHR$(19)
340 LOCATE 10, 40: PRINT T
350 '
355 '----------- MAIN STRATEGY LOOP ------------
356 '
360 FOR I = 10 TO 100 STEP 2
370    GOSUB 600'PICK UP PLAYER INPUT
380    T = T - P: LOCATE I + 1, 40: PRINT T;
390    IF T = 0 THEN WIN$ = PC$: GOTO 480
400    C = T - ((M + 1) * INT((T - 1) / (M + 1)) + 1)
410    IF C = 0 THEN C = INT(1 + M * RND)
420    IF T = 1 THEN C = 1
430    T = T - C
440    LOCATE I + 1, 58: PRINT "PC SUBTRACTS "; C;
450    LOCATE I + 2, 40: PRINT T;
460    IF T = 0 THEN WIN$ = PLAYER$: GOTO 480
470 NEXT I
475 '
476 '--- ANNOUNCE WINNER, SOUND OFF, DISPLAY OPTIONS ---
477 '
480 COLOR 0, 7: LOCATE 8, 31: PRINT STRING$(4, 32); WIN$; STRING$(5, 32)
482 FOR K = 1 TO 2
484    FOR J = 3000 TO 400 STEP -300
486    SOUND J, .5
488 NEXT J, K
490 COLOR 7, 0: LOCATE 25, 17
500 PRINT "PRESS R TO RUN PROGRAM AGAIN, Q TO QUIT GAME";
520 WHILE (X$ <> "q" AND X$ <> "Q")
530    X$ = INPUT$(1)
540    IF (X$ = "R" OR X$ = "r") THEN CLEAR : GOTO 10
570 WEND
580 CLS : RUN "GAMEMENU.EXE"
585 '
586 '------------ PLAYER-INPUT SUBROUTINE -------------
590 '
600 X = 100
610 WHILE 1
620    LOCATE I, 7, 1: PRINT "YOU SUBTRACT? ";
625    P = VAL(INPUT$(1)): PRINT P: LOCATE , , 0
630    IF P >= 1 AND P <= M AND P <= T THEN GOTO 690
640    IF M < T THEN X = M ELSE X = T
650    BEEP: LOCATE 25, 11: COLOR 15, 0
660    PRINT "IMPROPER INPUT. PLEASE ENTER AN INTERGER IN THE RANGE 1 -"; X;
670    COLOR 7, 0: LOCATE I, 7: PRINT STRING$(18, 32)
680 WEND
690 IF X < 100 THEN KEY ON: KEY OFF
700 RETURN

